package cn.han.date;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
/*Date -> String*/
//本类用于练习日期转换类simpleDateFormat
public class TestSDF {
    public static void main(String[] args) throws ParseException {
        Date d1 = new Date();
        //创建日期转换工具类的对象
        SimpleDateFormat sdf = new SimpleDateFormat();

        String s = sdf.format(d1);
        System.out.println(s);//21-9-24 下午5:22
        //创建日期转换工具类的对象
        SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy/MM/dd hh:mm:ss");
        String s1 = sdf1.format(d1);
        System.out.println(s1);
        /*Date <- String*/
        String s2 = "2021/09/24 05:29:43";
        SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy/MM/dd hh:mm:ss");
        Date d3 = sdf2.parse(s2);
        System.out.println(d3);

    }
}
